import React, { useState, useEffect, useRef } from 'react';
import { createModel } from 'hox';
import { message } from 'antd';
import { getAllFsuType, add } from '../service.js';
import { useRequest } from '@umijs/hooks';

function useAddModel() {
  const [visible, setVisible] = useState(false);
  const [deviceTypeList, setDeviceTypeList] = useState([]);
  //   //获取全部流程
  //   const { run: getFlowList } = useRequest(getFlowAll, {
  //     manual: true,
  //     onSuccess: async (res, params) => {
  //       if (res.result) {
  //         setFlowList(res.data || []);
  //       } else {
  //         message.error(res.msg);
  //       }
  //     },
  //   });
  //新增
  const { run: addDev, loading: addLoading } = useRequest(add, {
    manual: true,
    onSuccess: (res, params) => {
      if (res.result) {
      } else {
        message.error(res.msg);
      }
    },
  });
  //获取设备类型
  const { run: getDeviceType } = useRequest(getAllFsuType, {
    manual: true,
    onSuccess: (res, params) => {
      if (res.result) {
        setDeviceTypeList(res?.data || []);
      }
    },
  });
  return {
    visible,
    setVisible,
    getDeviceType,
    deviceTypeList,
    addDev,
    addLoading,
  };
}

export default createModel(useAddModel);
